wolfSSL_X509_verify_cert: add host check from ctx->param#9952
wolfSSL_X509_verify_cert: add host check from ctx->param#9952julek-wolfssl wants to merge 3 commits intowolfSSL:masterfrom
ctx->param#9952Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds OpenSSL-compatible hostname/IP enforcement to wolfSSL_X509_verify_cert() based on values set in WOLFSSL_X509_STORE_CTX->param, and introduces a regression test to ensure hostname mismatches are rejected.
Changes:
- Enforce hostname (
hostName) and IP (ipasc) checks duringwolfSSL_X509_verify_cert()when configured viaX509_VERIFY_PARAM. - Add a regression test that verifies hostname match/mismatch behavior and the resulting error code.
- Register the new test in the API test declarations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/x509_str.c |
Adds hostname/IP enforcement to wolfSSL_X509_verify_cert() when ctx->param is configured. |
tests/api/test_x509.c |
Adds a regression test covering success with no hostname, success with matching SAN DNS, and failure on mismatch. |
tests/api/test_x509.h |
Exposes and registers the new test in the x509 test group. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| ExpectIntNE(wolfSSL_X509_verify_cert(ctx), WOLFSSL_SUCCESS); | ||
| ExpectIntEQ(wolfSSL_X509_STORE_CTX_get_error(ctx), | ||
| X509_V_ERR_HOSTNAME_MISMATCH); | ||
| ExpectIntEQ(wolfSSL_X509_STORE_CTX_get_error_depth(ctx), 0); |
| /* Enforce hostname / IP verification from X509_VERIFY_PARAM if set. */ | ||
| if (ret == WOLFSSL_SUCCESS && ctx->param != NULL) { | ||
| if (ctx->param->hostName[0] != '\0') { | ||
| if (wolfSSL_X509_check_host(ctx->current_cert, | ||
| ctx->param->hostName, | ||
| XSTRLEN(ctx->param->hostName), | ||
| ctx->param->hostFlags, NULL) != WOLFSSL_SUCCESS) { | ||
| #ifndef OPENSSL_COEXIST | ||
| ctx->error = X509_V_ERR_HOSTNAME_MISMATCH; | ||
| #else | ||
| ctx->error = 1; /* Return generic error */ | ||
| #endif | ||
| ctx->error_depth = 0; | ||
| ret = WOLFSSL_FAILURE; | ||
| } | ||
| } | ||
| else if (ctx->param->ipasc[0] != '\0') { | ||
| if (wolfSSL_X509_check_ip_asc(ctx->current_cert, | ||
| ctx->param->ipasc, | ||
| ctx->param->hostFlags) != WOLFSSL_SUCCESS) { | ||
| #ifndef OPENSSL_COEXIST | ||
| ctx->error = X509_V_ERR_IP_ADDRESS_MISMATCH; | ||
| #else | ||
| ctx->error = 1; /* Return generic error */ | ||
| #endif | ||
| ctx->error_depth = 0; | ||
| ret = WOLFSSL_FAILURE; | ||
| } | ||
| } | ||
| } |
ZD21324